<?php

namespace app\api\controller;

use app\services\TextService;
use support\Request;

class TextController
{
    public function categories(Request $request)
    {
        try {
            $data = TextService::categories();

            return ok_rsp('成功', ['categories' => $data]);
        } catch (\Exception $e) {
            return e_rsp($e);
        }
    }

    public function list(Request $request)
    {
        try {
            $page = $request->post('page', 1);
            $length = $request->post('length', 10);
            $categoryId = $request->post('category_id', 0);

            $data = TextService::list($page, $length, $categoryId);

            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            return e_rsp($e);
        }
    }

    public function detail(Request $request)
    {
        try {
            $id = $request->post('id', 0);
            $data = TextService::detail($id);

            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            return e_rsp($e);
        }
    }
}